#include "CProcTextureBump.h"
#include "CPerlinNoise.h"
 
CProcTextureBump::CProcTextureBump(float persistance, int octave, float intensity): m_persistance(persistance),
				m_octave(octave), m_intensity(intensity){}


CColor CProcTextureBump::getColor(const CVector3f& p)const
{

	CVector3f newP = m_transform * p;

	const double delta = 0.1;

	CColor bump;
	CVector3f positionPlus = newP;
	CVector3f positionMinus = newP;
	positionPlus.x -= (float)delta;
	positionMinus.x += (float)delta;

	bump.RTVEC4X = CPerlinNoise::perlin(positionMinus, m_persistance, m_octave) * m_intensity - 
		CPerlinNoise::perlin(positionPlus, m_persistance, m_octave) * m_intensity;

	positionPlus = p;
	positionMinus = p;
	positionPlus.y -= (float)delta;
	positionMinus.y += (float)delta;

	bump.RTVEC4Y = CPerlinNoise::perlin(positionMinus, m_persistance, m_octave) * m_intensity - 
		CPerlinNoise::perlin(positionPlus, m_persistance, m_octave) * m_intensity;

	positionPlus = p;
	positionMinus = p;
	positionPlus.z -= (float)delta;
	positionMinus.z += (float)delta;

	bump.RTVEC4Z = CPerlinNoise::perlin(positionMinus, m_persistance, m_octave) * m_intensity - 
		CPerlinNoise::perlin(positionPlus, m_persistance, m_octave) * m_intensity;

	bump.normalize();

	return bump;
}